package org.iks.common.aop.serializer;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.iks.common.enums.ChatMessageType;

import java.io.IOException;

/**
 * Author kzou
 * Date 2024/3/23
 * Description: 自定义Json反序列化
 *
 * @see ChatMessageType
 */
public class ChatMessageTypeDeserializer extends JsonDeserializer<ChatMessageType> {

    @Override
    public ChatMessageType deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
        String value = jsonParser.getText();
        int code = Integer.parseInt(value);
        return ChatMessageType.of(code);
    }

}
